

import java.util.Scanner;

public class Shopping {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        double toothbrush = 8.8;
        double towel = 10.0;
        double cup = 18.8;
        double apple = 12.5;
        double banana = 15.5;
        System.out.println("-------------黑马小商城-------------");
        System.out.println("1.牙刷的价格为：" + toothbrush + "元");
        System.out.println("2.毛巾的价格为：" + towel + "元");
        System.out.println("3.水杯的价格为：" + cup + "元");
        System.out.println("4.苹果的价格为：" + apple + "元");
        System.out.println("5.香蕉的价格为：" + banana + "元");
        System.out.println("--------------------------------");
        int item;//购买商品序列号
        int count;//购买商品的数量
        double total = 0;
        String good = "商品名";
        String goods = "商品量词";
        double price = 0;
        String choice = "Y";
        do {
            System.out.println("请输入你需要购买商品的序列号");
            item = scanner.nextInt();
            switch (item) {
                case 1:
                    good = "牙刷";
                    goods = "把";
                    price = toothbrush;
                    break;
                case 2:
                    good = "毛巾";
                    goods = "条";
                    price = towel;
                    break;
                case 3:
                    good = "水杯";
                    goods = "个";
                    price = cup;
                    break;
                case 4:
                    good = "苹果";
                    goods = "斤";
                    price = apple;
                    break;
                case 5:
                    good = "香蕉";
                    goods = "斤";
                    price = banana;
                    break;
                default:
                    item = 0;
                    System.out.println("商品序号输入错误");

            }
            if (item != 0) {
                System.out.println("请输入你需要购买" + good + "的数量:");
                count = scanner.nextInt();
                total = total +count * price;
                System.out.println("你购买了" + good + count + goods + "花费了" + count*price + "元");


            }
            System.out.println("需要继续购买请输入Y，否则输入N：");
            choice = scanner.next();
            while (!choice.equals("Y") && !choice.equals("N")) {
                System.out.println("--------是否继续购买识别失败--------");
                System.out.print("需要继续购买请输入Y，否则输入N：");
                choice = scanner.next();

            }

        } while (choice.equals("Y"));//输入"Y"循环继续，输入"N"循环退出
        System.out.println("您本次购物共花费 " + total + " 元");
        System.out.println("期待您的下次光临！");
    }
}
